"""
Django生产环境设置
妙趣拾光锦盒用户系统的生产环境配置
"""

from boxuser.settings import *

# 关闭调试模式
DEBUG = False

# 允许的主机
ALLOWED_HOSTS = ['*']  # 实际部署时应改为具体域名

# 安全设置
SECURE_SSL_REDIRECT = True  # 重定向HTTP到HTTPS
SESSION_COOKIE_SECURE = True  # 只通过HTTPS发送cookie
CSRF_COOKIE_SECURE = True  # 只通过HTTPS发送CSRF cookie
SECURE_HSTS_SECONDS = 31536000  # 一年
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_PRELOAD = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# 禁用调试工具栏
INSTALLED_APPS = [app for app in INSTALLED_APPS if app != 'debug_toolbar']
MIDDLEWARE = [m for m in MIDDLEWARE if not m.startswith('debug_toolbar.')]

# 邮件配置
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.example.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'noreply@miaoqushiguang.com'
EMAIL_HOST_PASSWORD = '邮箱密码'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'noreply@miaoqushiguang.com'

# 会话和缓存配置
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
SESSION_CACHE_ALIAS = 'default'

# 缓存配置
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.PyMemcacheCache',
        'LOCATION': '127.0.0.1:11211',
    }
}

# 静态文件配置
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# 日志配置
LOGGING['handlers']['file']['level'] = 'WARNING'
LOGGING['loggers']['django']['level'] = 'WARNING'

# 行为跟踪设置
BEHAVIOR_TRACKING['ENABLED'] = True

# 替换SECRET_KEY
SECRET_KEY = env('SECRET_KEY')  # 确保环境变量中设置了这个值

# 数据库连接池
DATABASES['default']['CONN_MAX_AGE'] = 60  # 连接最大存活时间（秒） 